package Caracteristica;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import Util.Conexao;
import Util.HibernateUtil;

import org.hibernate.Criteria;

import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.sun.org.apache.bcel.internal.generic.GETSTATIC;

public class CaracteristicaDao {
	private static final long serialVersionUID = 1L;
	Conexao cx = new Conexao();
	
	private Session sessao ;
	private Session sessao1;
	 private Transaction trans;
	
	public void AddCaracteristica(Caracteristica ca)
	{
		cx.OpenConection();
		cx.getSessao().save(ca);
		cx.CloseConection();
	}
	public void RemoveCaracteristica (Caracteristica ca)
	{	
		cx.OpenConection();
		cx.getSessao().delete(ca);
		cx.CloseConection(); 
	}
	public void UpdateCaracteristica (Caracteristica ca)
	{
		cx.OpenConection();
		cx.getSessao().merge(ca);
		cx.CloseConection(); 
	}
	public List <Caracteristica> ListarCarcteristica()
	{
		Criteria listCa = cx.getTransacao().createCriteria(Caracteristica.class);
		listCa.addOrder(Order.asc("dscCaractristica"));
		return listCa.list();
	}
	public List <Caracteristica> ListarCarcteristicaDSC(String dsc)
	{
		Criteria listCa = cx.getTransacao().createCriteria(Caracteristica.class);
		listCa.add(Restrictions.like("dscCaractristica", "%" + dsc + "%"));
		listCa.addOrder(Order.asc("dscCaractristica"));
		return listCa.list();
	}
	public Caracteristica listarCaracteristica (int cod)
	{
		Criteria listCa = cx.getTransacao().createCriteria(Caracteristica.class);
		listCa.add(Restrictions.eq("codCarcateristica", cod));
		return (Caracteristica)listCa.uniqueResult();
	}
	
}
